package cn.guozeyiblog.client;

import java.util.List;

import cn.guozeyiblog.blogutils.ArticleDetail;
import cn.guozeyiblog.client.R;
import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

@SuppressLint("ViewHolder")
/**
 * 放在ＸlistView中的数据
 * @author kutear
 *
 */
public class ArticleAdapter extends BaseAdapter {
	
	private List<ArticleDetail> articleList;
	private Context context;
	
	
	
	public ArticleAdapter(List<ArticleDetail> list,Context context) {
		// TODO Auto-generated constructor stub
		this.articleList = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return articleList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return articleList.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		LinearLayout layout;
		if (convertView==null) {
			LayoutInflater inflater = LayoutInflater.from(context);
			layout = (LinearLayout) inflater.inflate(R.layout.article_item, null);
		}else {
			layout = (LinearLayout) convertView;
		}
		TextView titleText = (TextView) layout.findViewById(R.id.article_title);
		TextView dateText = (TextView) layout.findViewById(R.id.article_date);
		TextView viewCountText = (TextView) layout.findViewById(R.id.view_count);
		TextView commentCountText = (TextView) layout.findViewById(R.id.comment_count);
		TextView descriptionText = (TextView) layout.findViewById(R.id.article_description);
		
		titleText.setText(articleList.get(position).getTitle());
		dateText.setText(articleList.get(position).getDate());
		viewCountText.setText(articleList.get(position).getViewCount());
		commentCountText.setText(articleList.get(position).getCommentCount());
		descriptionText.setText(articleList.get(position).getDescription());

		return layout;
	}

}
